package com.soft.javase.day15.annotations;

import java.lang.reflect.Method;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/5/27
 */
public class TestRunner {
    public static void runTest(Class<?> testClass) {
        System.out.println("Run test for: " + testClass.getSimpleName());

        int passed = 0;
        int failed = 0;

        for (Method method : testClass.getDeclaredMethods()) {
            if (method.isAnnotationPresent(MyTest.class)) {
                System.out.print("Run " + method.getName() + "... ");

                try {
                    Object testInstance = testClass.getDeclaredConstructor().newInstance();
                    method.invoke(testInstance);
                    System.out.println("PASSED");
                    passed++;
                } catch (Exception e) {
                    System.out.println("FAILED: " + e.getCause());
                    failed++;
                }
            }
        }

        System.out.println("Result: " + passed + "passed," + failed + "failed");
    }
}
